#This file holds the post class and the post status enum.

#Full Posts Status strings as they appear in the .csv datasets
class FullPostStatus:
	POST_OPEN = "open"
	POST_OFF_TOPIC = "off topic"
	POST_NOT_CONSTRUCTIVE = "not constructive"
	POST_NOT_A_REAL_QUESTION = "not a real question"
	POST_TOO_LOCALIZED = "too localized"

#An enum for each post status
class PostStatusEnum:
	OPEN = 1
	OFF_TOPIC = 2
	NOT_CONSTRUCTIVE = 3
	NOT_A_REAL_QUESTION = 4
	TOO_LOCALIZED = 5

#Converts from a post status enum to the correct full string
def getFullPostStatus(postStatusEnum):
	return {
		PostStatusEnum.OPEN                : FullPostStatus.POST_OPEN,
		PostStatusEnum.OFF_TOPIC           : FullPostStatus.POST_OFF_TOPIC,
		PostStatusEnum.NOT_CONSTRUCTIVE    : FullPostStatus.POST_NOT_CONSTRUCTIVE,
		PostStatusEnum.NOT_A_REAL_QUESTION : FullPostStatus.POST_NOT_A_REAL_QUESTION,
		PostStatusEnum.TOO_LOCALIZED       : FullPostStatus.POST_TOO_LOCALIZED,
	}[postStatusEnum]

#Converts from a full string post status to the correct enum
def getPostStatusEnum(fullPostStatus):
	return {
		FullPostStatus.POST_OPEN                : PostStatusEnum.OPEN,
		FullPostStatus.POST_OFF_TOPIC           : PostStatusEnum.OFF_TOPIC,
		FullPostStatus.POST_NOT_CONSTRUCTIVE    : PostStatusEnum.NOT_CONSTRUCTIVE,
		FullPostStatus.POST_NOT_A_REAL_QUESTION : PostStatusEnum.NOT_A_REAL_QUESTION,
		FullPostStatus.POST_TOO_LOCALIZED       : PostStatusEnum.TOO_LOCALIZED,
	}[fullPostStatus.rstrip()]

#Post class containing all post attributes contained in the dataset
class Post:
	#Constructor
	def __init__(self, postID, postCreationDate, ownerUserId, ownerCreationDate, reputationAtPostCreation, ownerUndeletedAnswerCountAtPostTime, title, bodyMarkdown, tag1, tag2, tag3, tag4, tag5, postClosedDate, openStatus):
		self.postID = postID
		self.postCreationDate = postCreationDate
		self.ownerUserId = ownerUserId
		self.ownerCreationDate = ownerCreationDate
		self.reputationAtPostCreation = reputationAtPostCreation
		self.ownerUndeletedAnswerCountAtPostTime = ownerUndeletedAnswerCountAtPostTime
		self.title = title
		self.bodyMarkdown = bodyMarkdown
		self.tag1 = tag1
		self.tag2 = tag2
		self.tag3 = tag3
		self.tag4 = tag4
		self.tag5 = tag5
		self.postClosedDate = postClosedDate
		self.openStatus = getPostStatusEnum(openStatus)
	
	#Prints the post as a string for debugging purposes.
	def toTestLine(self):
		return str(self.postID) + "," + str(self.postCreationDate) + "," + str(self.ownerUserId) + "," + str(self.ownerCreationDate) + "," + str(self.reputationAtPostCreation) + "," + str(self.ownerUndeletedAnswerCountAtPostTime) + ",\"" + str(self.title.replace("\"","\"\"")) + "\",\"" + str(self.bodyMarkdown.replace("\"","\"\"")) + "\"," + str(self.tag1) + "," + str(self.tag2) + "," + str(self.tag3) + "," + str(self.tag4) + "," + str(self.tag5) + "\n"
	
	#Prints the post as a string for debugging purposes.
	def toLine(self):
		return str(self.postID) + "," + str(self.postCreationDate) + "," + str(self.ownerUserId) + "," + str(self.ownerCreationDate) + "," + str(self.reputationAtPostCreation) + "," + str(self.ownerUndeletedAnswerCountAtPostTime) + ",\"" + str(self.title.replace("\"","\"\"")) + "\",\"" + str(self.bodyMarkdown.replace("\"","\"\"")) + "\"," + str(self.tag1) + "," + str(self.tag2) + "," + str(self.tag3) + "," + str(self.tag4) + "," + str(self.tag5) + "," + str(self.postClosedDate) + "," + str(getFullPostStatus(self.openStatus)) + "\n"